/**
 * AttendanceController
 *
 * @description :: Server-side logic for managing attendances
 * @help        :: See http://sailsjs.org/#!/documentation/concepts/Controllers
 */

module.exports = {
	  query:function(req,res){
        //   console.log('12345')
          let id=req.body.id;
          let date=req.body.date;
          Database.find(TeacherCheckFinal,{id}).then((data)=>{
              res.json({
                  success:true,
                  data:data
              })
          }).catch((e)=>{
              console.log(e);
              res.json({
                  success:false
              });
          })
      },
      in:function(req,res){
          console.log(req.body);
          let from=req.body.from;
          let to=req.body.to;
          let tag = req.body.tag;
          if( !from || !to || !tag){
              res.json({
                  success:false
              });
              return;
          }
          Database.find(TeacherCheckFinal,{'Date':{'>=':from,'<=':to},Tags:{'contains':tag}}).then((data)=>{
              res.json({
                  success:true,
                  data:data
              })
          }).catch((e)=>{
              console.log(e);
              res.json({
                  success:false
              });
          })
      },
      output:function(req,res){
        let data = req.body.data;
        let info = req.body.info;
        if( !data || !info){
            res.status(503).end();
            return;
        }
        let inputData = [data,info];
         AttendanceService.process(inputData,(data)=>{
            res.setHeader('content-type','text/plain');
            res.send(data);
            res.end();
         },()=>{
            res.status(503).end();
         })
      }
};
